package sz.szsmk.citizencard.mvp.presenter;

import android.util.Log;
import android.widget.TableRow;

import com.google.gson.Gson;

import javax.inject.Inject;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.QueryCollectedStandreq;
import sz.szsmk.citizencard.model.network.bean.request.QueryUserCardRequest;
import sz.szsmk.citizencard.model.network.bean.response.QueryNearStandbyRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryUserCardRes;
import sz.szsmk.citizencard.mvp.contract.IBusSiteCollectContact;
import sz.szsmk.citizencard.mvp.contract.ICardListCardsContact;
import sz.szsmk.citizencard.mvp.contract.IChargeContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.Constant;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/15 9:52
 * description:
 */
public class CardsListCardsPresenter extends IBasePresenter
implements ICardListCardsContact.ICardListCardsPresenter<ICardListCardsContact.ICardListCardsView> {


    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public CardsListCardsPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void queryUserCard(String origin) {

        QueryUserCardRequest cardRequest = new QueryUserCardRequest();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        cardRequest.setAccess_token(access_token);
        cardRequest.setType("0");
        cardRequest.setOrigin(origin);
        String json = new Gson().toJson(cardRequest);
        Log.e("queryUserCard->",json);
        mNetworkDateSource.queryUserCardInfo(cardRequest, new SubscribeResult<QueryUserCardRes>() {
            @Override
            protected void onOk(QueryUserCardRes response) {
                String json = new Gson().toJson(response);
                L.e(Constant.TAG, "queryUserCard----->" + json);
                ((ICardListCardsContact.ICardListCardsView)mView).getDataListSucc(response);
            }

            @Override
            protected void onFailure(QueryUserCardRes response) {
                super.onFailure(response);
                ((ICardListCardsContact.ICardListCardsView)mView).getDataListFail();

            }

            @Override
            protected void onNext(QueryUserCardRes response) {
                super.onNext(response);
                ((ICardListCardsContact.ICardListCardsView)mView).getDataListFail();
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                Log.d("clark",throwable.getMessage());
                ((ICardListCardsContact.ICardListCardsView)mView).getDataListFail();
            }
        });
    }

}
